package com.yuanshi.faceword

import org.apache.spark.sql.SparkSession

/**
  * 统计用户&内容运营excel表格中的 颜世界用户互动行为数据 的相关指标
  */
object FaceWordUserAct {

  def main(args: Array[String]): Unit = {
    val spark: SparkSession = SparkSession.builder().enableHiveSupport().config("hive.exec.dynamic.partition", true)
      .config("hive.exec.dynamic.partition.mode", "nonstrict").appName("FaceWordUserAct").getOrCreate()

    var dt: String = args(0)

    //统计颜世界日活与点击量，字段1，2
    spark.sql(
      s"""
        |select
        |count(distinct temporary_id),
        |count(distinct if(log_type = 2,temporary_id,null))
        |from
        |face_value_circle_video_play_info
        |where create_time = '${dt}'
      """.stripMargin)

    //统计点赞相关的字段，字段3，4，5，6，7，8，9
    spark.sql(
      s"""
        |select
        |sum(praise_number) as praise_total,
        |count(distinct tmp_id) as praise_user_total,
        |sum(praise_number)/count(if(play_number > 0,play_number,null)) as praise_rate,
        |sum(praise_number)/count(distinct tmp_id) as praise_user_avg,
        |sum(praise_number)/count(distinct if(praise_number > 0,tmp_id,null)) as join_user_avg,
        |sum(comment_number) as comment_total,
        |sum(comment_number)/count(distinct if(comment_number > 0,tmp_id,null)) as comment_user_avg
        |from
        |face_value_circle_video
        |where app_remark = 1 and create_time >= '${dt}' and create_time <= '${dt}'
      """.stripMargin)

    spark.close()
  }
}
